package org.paic.d;

import java.util.List;
import java.util.Map;

/**
 * 分页的逻辑对象
 * 
 * @author kerry
 */
public class Pager {
	// 当前页
	private int pageNum = 1;
	// 每页记录数
	private int pageSize = 10;
	// 总记录数
	private int totalCount = 0;
	// 结果集，类型匹配Sql查询返回的结果集
	private List<Map<String, Object>> ll;

	public Pager(int c, int n) {
		this.pageNum = c;
		this.pageSize = n;
	}

	/**
	 * 返回总页数
	 * 
	 * @return
	 */
	public int getTotalPage() {
		return this.totalCount % this.pageSize == 0 ? this.totalCount
				/ this.pageSize : this.totalCount / this.pageSize + 1;
	}

	/**
	 * 返回当前页的记录的开始下标
	 * 
	 * @return
	 */
	public int getStart() {
		return (this.pageNum - 1) * this.pageSize;
	}

	/**
	 * 返回当前页的记录的结束下标
	 * 
	 * @return
	 */
	public int getEnd() {
		if ((this.totalCount < this.pageSize) || (!hasNext())) {
			return this.totalCount;
		}
		return this.pageNum * this.pageSize;
	}

	/**
	 * 是否有下一页
	 * 
	 * @return
	 */
	public boolean hasNext() {
		return this.pageNum < getTotalPage();
	}

	/**
	 * 是否有上一页
	 * 
	 * @return
	 */
	public boolean hasPre() {
		return (this.pageNum > 1) && (getTotalPage() > 1);
	}

	public int getPageNum() {
		return this.pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return this.pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return this.totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public List<Map<String, Object>> getLl() {
		return this.ll;
	}

	public void setLl(List<Map<String, Object>> ll) {
		this.ll = ll;
	}
}
